<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../basePath.jsp"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="${basePath}statichcy/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${basePath}statichcy/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="${basePath}statichcy/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="${basePath}statichcy/css/style.css">
	<script src="${basePath}statichcy/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="${basePath}statichcy/plugins/bootstrap/js/bootstrap.min.js"></script>
 
</head>

<body class="hold-transition skin-red sidebar-mini" >
  <!-- .box-body -->
                
                    <div class="box-header with-border">
                        <h3 class="box-title">商品管理</h3>
                    </div>

                    <div class="box-body">

                        <!-- 数据表格 -->
                        <div class="table-box">

                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default" title="新建" data-toggle="modal"  data-target="#editModal" ><i class="fa fa-file-o"></i> 新建</button>
<%--                                        <button type="button" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>--%>
<%--                                        <button type="button" class="btn btn-default" title="提交审核" ><i class="fa fa-check"></i> 提交审核</button>--%>
<%--                                        <button type="button" class="btn btn-default" title="屏蔽" onclick='confirm("你确认要屏蔽吗？")'><i class="fa fa-ban"></i> 屏蔽</button>--%>
                                        <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
<%--                            <div class="box-tools pull-right">--%>
<%--                                <div class="has-feedback">--%>
<%--                                  状态：<select>--%>
<%--                                         	<option value="">全部</option>      --%>
<%--                                         	<option value="0">未申请</option>    --%>
<%--                                         	<option value="1">申请中</option>    --%>
<%--                                         	<option value="2">审核通过</option>    --%>
<%--                                         	<option value="3">已驳回</option>                                     --%>
<%--                                        </select>--%>
<%--							                  商品名称：<input >									--%>
<%--									<button class="btn btn-default" >查询</button>                                    --%>
<%--                                </div>--%>
<%--                            </div>--%>
                            <!--工具栏/-->

			                  <!--数据列表-->
			                  <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
			                      <thead>
			                          <tr>
<%--			                              <th class="" style="padding-right:0px">--%>
<%--			                                  <input id="selall" type="checkbox" class="icheckbox_square-blue">--%>
<%--			                              </th> --%>
										  <th class="sorting_asc">商品ID</th>
									      <th class="sorting">商品名称</th>
									      <th class="sorting">商品价格</th>
									      <th class="sorting">一级分类</th>
									      <th class="sorting">二级分类</th>
									      <th class="sorting">品牌</th>
<%--									      <th class="sorting">状态</th>									     						--%>
					                      <th class="text-center">操作</th>
			                          </tr>
			                      </thead>
			                      <tbody>
								  <c:forEach items="${items}" var="items">
			                          <tr>
<%--			                              <td><input id="sel" name="sal" value="${items.id}"  type="checkbox" ></td>--%>
				                          <td>${items.id}</td>
									      <td>${items.title}</td>
									      <td>${items.price}</td>
									      <td>${items.category}</td>
									      <td>${items.categoryId}</td>
									      <td>${items.brand}</td>
<%--										  <td></td>--%>
		                                  <td class="text-center">
<%--											  <button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal">增加</button>--%>
		                                 	  <button type="button" class="btn bg-olive btn-xs" onclick="toChange(${items.id})" data-toggle="modal" data-target="#editModal2">修改</button>
											  <button type="button" class="btn bg-olive btn-xs" onclick="del(${items.id})" data-toggle="modal">删除</button>
		                                  </td>
			                          </tr>
								  </c:forEach>
			                      </tbody>
			                  </table>
			                  <!--数据列表/-->                        
							  
							 
                        </div>
                        <!-- 数据表格 /-->
                        
                        
                     </div>
                    <!-- /.box-body -->
  <!-- 编辑窗口 -->
  <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	  <div class="modal-dialog">
		  <div class="modal-content">
			  <div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				  <h3 id="myModalLabel">新增商品</h3>
			  </div>
			  <div class="modal-body">
				  <table class="table table-bordered table-striped"  width="800px">
					  <tr>
						  <td>商品名称</td>
						  <td><input id="title" class="form-control" value="" placeholder="商品名称" />  </td>
					  </tr>
					  <tr>
						  <td>商品价格</td>
						  <td><input id="price" class="form-control"  value="" placeholder="商品价格" />  </td>
					  </tr>
					  <tr>
						  <td>存货</td>
						  <td><input id="num" class="form-control"  value="" placeholder="存货" />  </td>
					  </tr>
					  <tr>
						  <td>品牌</td>
						  <td><input id="brand" class="form-control"  value="" placeholder="品牌" />  </td>
					  </tr>
					  <tr>
						  <td>商家</td>
						  <td><input id="seller" class="form-control"  value="" placeholder="商家" />  </td>
					  </tr>
					  <tr>
						  <td>一级分类</td>
						  <td><input id="category" class="form-control"  value="" placeholder="一级分类" />  </td>
					  </tr>
					  <tr>
						  <td>二级分类</td>
						  <td><input id="categoryId" class="form-control"  value="" placeholder="二级分类" />  </td>
					  </tr>
				  </table>
			  </div>
			  <div class="modal-footer">
				  <input type="submit" class="btn btn-success" data-dismiss="modal" onclick="addItem()" value="保存" aria-hidden="true" >
				  <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
			  </div>
		  </div>
	  </div>
  </div>




  <div class="modal fade" id="editModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	  <div class="modal-dialog">
		  <div class="modal-content">
			  <div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				  <h3 id="myModalLabel2">商品编辑</h3>
			  </div>
			  <div class="modal-body">
				  <table class="table table-bordered table-striped"  width="800px">
					  <tr>
						  <td>商品名称</td>
						  <td><input id="title2" class="form-control" value="" placeholder="商品名称" >  </td>
					  </tr>
					  <tr>
						  <td>商品价格</td>
						  <td><input id="price2" class="form-control"  value="" placeholder="商品价格">  </td>
					  </tr>
					  <tr>
						  <td>存货</td>
						  <td><input id="num2" class="form-control"  value="" placeholder="存货">  </td>
					  </tr>
					  <tr>
						  <td>品牌</td>
						  <td><input id="brand2" class="form-control"  value="" placeholder="品牌" />  </td>
					  </tr>
					  <tr>
						  <td>一级分类</td>
						  <td><input id="category2" class="form-control"  value="" placeholder="一级分类">  </td>
					  </tr>
					  <tr>
						  <td>二级分类</td>
						  <td><input id="categoryId2" class="form-control"  value="" placeholder="二级分类">  </td>
					  </tr>
				  </table>
			  </div>
			  <div class="modal-footer">
				  <input type="submit" class="btn btn-success" data-dismiss="modal" onclick="updateItem()" value="保存" aria-hidden="true" />
				  <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
			  </div>
		  </div>
	  </div>
  </div>
</body>

<script type="text/javascript">

	var updateid;

	function addItem() {

		let title = document.getElementById("title").value;
		let price = document.getElementById("price").value;
		let num = document.getElementById("num").value;
		let brand = document.getElementById("brand").value;
		let seller = document.getElementById("seller").value;
		let category = document.getElementById("category").value;
		let categoryId = document.getElementById("categoryId").value;
		window.location.href="${basePath}Hcy2/addItem?title="+title+"&price="+price+"&num="+num+"&brand="+brand
				+"&seller="+seller+"&category="+category+"&categoryId="+categoryId;
	}

	function toChange(id) {

		let title2 = document.getElementById("title2");
		let price2 = document.getElementById("price2");
		let num2 = document.getElementById("num2");
		let brand2 = document.getElementById("brand2");
		let category2 = document.getElementById("category2");
		let categoryId2 = document.getElementById("categoryId2");

		$.get("${basePath}Hcy2/data?id="+id,function (data) {
			if (data) {
				title2.value = data.title;
				price2.value = data.price;
				num2.value = data.num;
				brand2.value = data.brand;
				category2.value = data.category;
				categoryId2.value = data.categoryId;

				updateid = data.id;

			} else {
				console.log("data为空");
			}
		});
	}

	function updateItem() {

		let id = updateid;
		let title2 = document.getElementById("title2").value;
		let price2 = document.getElementById("price2").value;
		let num2 = document.getElementById("num2").value;
		let brand2 = document.getElementById("brand2").value;
		let category2 = document.getElementById("category2").value;
		let categoryId2 = document.getElementById("categoryId2").value;

		window.location.href="${basePath}Hcy2/updateItem?id="+id+"&title2="+title2+"&price2="+price2+"&num2="+num2
				+"&brand2="+brand2+"&category2="+category2+"&categoryId2="+categoryId2;
		//
	}

	function del(id) {
		if (!confirm("确定要删除这个商品吗?")){
			return ;
		}
		window.location.href= "${basePath}Hcy2/del?id="+id

	}


</script>

</html>